// 插件基类
class BasePlugin {
  commands: any
  viewer: any
  widgetsManager: any
  eventsManager: any

  constructor() {
    this.commands = {}
    this.viewer = null
    this.widgetsManager = null
    this.eventsManager = null
  }

  // 初始化插件,无需复写
  register(viewer: any, widgetsManager: any, eventsManager: any) {
    this.viewer = viewer
    this.widgetsManager = widgetsManager
    this.eventsManager = eventsManager
    this.registerCommands()
    this.registerEvents()
  }

  // 注册命令,必须复写
  registerCommands() {
    throw new Error('子类必须重写父类的registerCommands方法')
  }

  // 添加命令
  addCommand(command: any) {
    const params = {
      viewer: this.viewer,
      widgetsManager: this.widgetsManager,
      eventsManager: this.eventsManager
    }
    const name = command.name
    this.commands[name] = new command(params)
    this.commands[name].register(params)
  }

  // 注册订阅事件，选择性复写
  registerEvents() { }

  // 订阅事件
  subscribeEvent(eventType: string) {
    this.eventsManager.on(eventType, this.handleEvent.bind(this, eventType))
  }

  // 接收事件，选择性复写
  handleEvent(eventType: string, args: any) {
    console.log('未定义接收事件函数')
  }
}

export default BasePlugin